package com.alibaba.springbootrbac.controller;

import com.alibaba.springbootrbac.model.entity.Role;
import com.alibaba.springbootrbac.model.param.role.*;
import com.alibaba.springbootrbac.service.RoleService;
import com.alibaba.springbootrbac.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZhouYaDong
 * @date 2025/8/22
 * @description 权限控制器
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @PostMapping("/addRole")
    public Result<String> addRole(@RequestBody @Validated RoleParam param){
        roleService.addRole(param);
        return Result.success("新增成功");
    }

    @PostMapping("/updateRoleById")
    public Result<String> updateRoleById(@RequestBody @Validated UpdateRoleParam param){
        roleService.updateRoleById(param);
        return Result.success("更新成功");
    }

    @PostMapping("/deleteRoleById")
    public Result<String> deleteRoleById(@RequestBody @Validated DeleteRoleParam param){
        roleService.deleteRoleById(param);
        return Result.success("删除成功");
    }

    @PostMapping("/queryRolesByPage")
    public Result<IPage<Role>> queryRolesByPage(@RequestBody @Validated RolePageQueryParam param){
        return Result.success(roleService.queryRolesByPage(param));
    }

    @PostMapping("/assignPermissionsToRole")
    public Result<String> assignPermissionsToRole(@RequestBody @Validated RolePermissionParam param){
        roleService.assignPermissionsToRole(param);
        return Result.success("分配权限成功");
    }

    @PostMapping("/removePermissionFromRole")
    public Result<String> removePermissionFromRole(@RequestBody @Validated RolePermissionParam param) {
        roleService.removePermissionFromRole(param);
        return Result.success("删除角色权限成功");
    }

    @PostMapping("/removePermissionsFromRole")
    public Result<String> removePermissionsFromRole(@RequestBody @Validated RolePermissionParam param) {
        roleService.removePermissionsFromRole(param);
        return Result.success("批量删除角色权限成功");
    }

}
